/**
 * Created with IntelliJ IDEA.
 * User: mgm
 * Date: 2019-05-10
 * Time: 1:38
 */
public class SyncWait {
    public static void main(String[] args) {
        final String str = "str";
        SyncWait wait = new SyncWait();

        Thread threadW =  new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait");
                synchronized (str) {
                    try {
                        str.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });

        threadW.start();

        Thread thread =  new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("notify");
                synchronized (str) {
                    str.notify();
                }

            }
        });

        thread.start();
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("sleep end");
//        thread.interrupt();
        synchronized (str) {
            System.out.println("inter");
            threadW.interrupt();

        }


        System.out.println("notified!");
    }
}
